package com.ocom.xfrecode.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ocom.common.entity.card.EntityXfGoodListOrg;
import com.ocom.common.vo.xfrecode.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface XfGoodListOrgMapper extends BaseMapper<EntityXfGoodListOrg> {

//    @Select({"<script>",
//            "SELECT " +
//                    " point_id, " +
//                    " meal_date, " +
//                    " meal_no, " +
//                    " sum(case when if_refund=0 then 1 else 0 end )  AS dcTimes, " +
//                    " sum(case when if_refund=0 then 0 else 1 end ) as tcTimes " +
//                    " FROM " +
//                    " ( " +
//                    "  SELECT " +
//                    "   point_id, " +
//                    "   meal_date, " +
//                    "   meal_no, " +
//                    "   order_no, " +
//                    "   sum(if_refund) as  if_refund " +
//                    "  FROM " +
//                    "   ocom_saas_xfrecord_${database}.xf_goods_list_${monthValue} " +
//                    "   WHERE " +
//                    "    com_id = #{comId} " +
//                    " <when test=\"pointId != null\" > " +
//                    "   AND point_id = #{pointId} " +
//                    " </when> " +
//                    "   AND meal_date between #{startTime}  and  #{endTime} " +
//                    "  GROUP BY " +
//                    "   point_id, " +
//                    "   meal_date, " +
//                    "   meal_no, " +
//                    "   order_no " +
//                    " ) T " +
//                    "GROUP BY " +
//                    " point_id, " +
//                    " meal_date, " +
//                    " meal_no " +
//                    "ORDER BY " +
//                    " point_id, " +
//                    " meal_date, " +
//                    " meal_no " +
//                    "</script>"})
//    List<GetPointMealPreVo> getPointMealPre(@Param("comId") Long comId, @Param("pointId") Long pointId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("monthValue") String monthValue, @Param("database") String database);

//    @Select({"<script>",
//            "SELECT " +
//                    " point_id, " +
//                    " receipt_id, " +
//                    " receipt_name, " +
//                    " meal_date, " +
//                    " meal_no, " +
//                    " sum(case when if_refund=0 then 1 else 0 end )  AS dcTimes, " +
//                    " sum(case when if_refund=0 then 0 else 1 end ) as tcTimes " +
//                    "FROM " +
//                    " ( " +
//                    "  SELECT " +
//                    "   point_id, " +
//                    "   receipt_id, " +
//                    "   receipt_name, " +
//                    "   meal_date, " +
//                    "   meal_no, " +
//                    "   order_no, " +
//                    "   sum(if_refund) as if_refund " +
//                    "  FROM " +
//                    "   ocom_saas_xfrecord_${database}.xf_goods_list_${monthValue} " +
//                    "  WHERE " +
//                    "    com_id = #{comId} " +
//                    " <when test=\"pointId != null\" > " +
//                    "   AND point_id = #{pointId} " +
//                    " </when> " +
//                    " <when test=\"receiptId != null\" > " +
//                    "   AND receipt_id = #{receiptId} " +
//                    " </when> " +
//                    "   AND meal_date between #{startTime}  and  #{endTime} " +
//                    " <when test=\"receiptName != null\" > " +
//                    "  AND receipt_name LIKE '%#{receiptName}%' " +
//                    " </when> " +
//                    "  GROUP BY " +
//                    "   point_id, " +
//                    "   receipt_id, " +
////                    "   receipt_name, " +
//                    "   meal_date, " +
//                    "   meal_no, " +
//                    "   order_no " +
//                    " ) T " +
//                    "GROUP BY " +
//                    " point_id, " +
//                    " receipt_id, " +
////                    " receipt_name, " +
//                    " meal_date, " +
//                    " meal_no " +
//                    "ORDER BY " +
//                    " point_id, " +
//                    " receipt_id, " +
////                    " receipt_name, " +
//                    " meal_date, " +
//                    " meal_no" +
//                    "</script>"})
//    List<GetPointMealSendVo> getPointMealSend(@Param("comId") Long comId, @Param("pointId") Long pointId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("receiptId") Long receiptId, @Param("receiptName") String receiptName, @Param("monthValue") String monthValue, @Param("database") String database);
    @Select("SELECT ${ew.sqlSelect} FROM xf_goods_list ${ew.customSqlSegment} ")
    List<GetMealPreReportsXMVo> getMealPreReportsXM(@Param(Constants.WRAPPER) Wrapper wrapper);

    @Select("SELECT ${ew.sqlSelect} FROM xf_goods_list ${ew.customSqlSegment} ")
    List<GetMealSendReportsXMByOneVo> GetMealSendReportsXMByOne(@Param(Constants.WRAPPER) Wrapper wrapper);

    @Select("SELECT ${ew.sqlSelect} FROM xf_goods_list ${ew.customSqlSegment} ")
    List<GetMealSendReportsXMByTwoVo> GetMealSendReportsXMByTwo(@Param(Constants.WRAPPER) Wrapper wrapper);

    @Select("select r.id,r.com_id,r.device_no,r.device_name,r.dept_id,r.dept_name,r.p_id,r.p_name,r.p_code,r.order_no,r.cons_state,r.sub_account,r.face,r.if_refund,r.device_no,r.device_name,r.cons_time,r.pay_time,r.op_type,r.op_type_diff,r.cons_money,r.discount,r.real_money,g.dishes_name ,g.weight_number,r.create_time,r.charge_money,r.discount_way,r.sub_money " +
            "from xf_record r " +
            "left join xf_goods_list g on r.com_id=g.com_id and r.order_no=g.order_no  ${ew.customSqlSegment} ")
    IPage<GetPerVideoListVo> getPerVideoPage(Page<GetPerVideoListVo> page, @Param(Constants.WRAPPER) Wrapper wrapper);

    @Select("select r.id,r.com_id,r.device_no,r.device_name,r.dept_id,r.dept_name,r.p_id,r.p_name,r.p_code,r.order_no,r.cons_state,r.sub_account,r.face,r.if_refund,r.device_no,r.device_name,r.cons_time,r.pay_time,r.op_type,r.op_type_diff,r.cons_money,r.discount,r.real_money,g.dishes_name ,g.weight_number,r.create_time,r.charge_money,r.discount_way,r.sub_money " +
            "from xf_record r " +
            "left join xf_goods_list g on r.com_id=g.com_id and r.order_no=g.order_no  ${ew.customSqlSegment} ")
    List<GetPerVideoListVo> getPerVideoList(@Param(Constants.WRAPPER) Wrapper wrapper);
}
